using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using Android.Graphics.Drawables;

namespace CPXamarin
{
    public class RoundAvatar
    {
        public static Bitmap GetRoundBitmap(Bitmap scaleBitmapImage)
        {
            int targetWidth = 1000;
            int targetHeight = 1000;

            Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight,Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(targetBitmap);
            Path path = new Path();
            path.AddCircle(((float)targetWidth - 1) / 2,((float)targetHeight - 1) / 2,(Math.Min(((float)targetWidth), ((float)targetHeight)) / 2),Path.Direction.Ccw);
            canvas.ClipPath(path);
            Bitmap sourceBitmap = scaleBitmapImage;
            canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width,sourceBitmap.Height), new Rect(0, 0, targetWidth,targetHeight), null);
            return targetBitmap;
        }

        public static Drawable GetRoundDrawable(Drawable d)
        {
            Bitmap b = GetRoundBitmap(((BitmapDrawable)d).Bitmap);
            return new BitmapDrawable(b);
        }
    }
}